from django.db import models
from django.contrib.auth.models import User
# import datetime

# Create your models here.
class BookShelf(models.Model):
    LABRARY_CHOICES = (
        ('1', '东馆'),
        ('2', '西馆'),
        ('3', '南馆'),
        ('4', '北馆'),
    )
    name = models.CharField(max_length=200)
    labrary_belonged_to = models.CharField(max_length=2, verbose_name='位置', choices=LABRARY_CHOICES, blank=True)
    books_in_layer = models.IntegerField(default=0)

    def __str__(self):
        return self.name

class Book(models.Model):
    STATE_CHOICES = (
		(True, '外借'),
		(False, '在架'),
	)
    name = models.CharField(max_length=200)
    book_type = models.CharField(max_length=200, default=None)
    numbers = models.IntegerField(default=0)
    date_added = models.DateTimeField(auto_now_add=True)
    outs_ins = models.DateTimeField(verbose_name='借还时间', auto_now=True)
    state = models.BooleanField(verbose_name='状态', choices=STATE_CHOICES, default=False)
    times = models.IntegerField(default=0)
    owner = models.ForeignKey(
        User, 
        blank=True, 
        null=True, 
        on_delete=models.SET_NULL
        )
    stock_position = models.ForeignKey(BookShelf, on_delete=models.CASCADE)

    def __str__(self):
        return self.name

class TimeManage(models.Model):
    STATE_CHOICES = (
        (True, '外借'),
        (False, '归还'),
    )
    name = models.ForeignKey(Book, on_delete=models.CASCADE)
    outs_ins = models.DateTimeField(verbose_name='借还时间', auto_now=True)
    state = models.BooleanField(verbose_name='状态', choices=STATE_CHOICES, default=False)

    def __str__(self):
        return self.name.name